<script>
  import OnSiteCheckReport from './components/onSiteCheckReport.vue';
  import Session from './components/session.vue'
  import {
		workOrderInfo,
    foodProductionInfo
	} from '@/api/order'

  export default {
    components: {
      OnSiteCheckReport,
      Session
    },
    data(){
      return {
        workOrderDetail: {},
        components: null,
        editStatus: '',
        categoryDetail: {}
      }
    },
    onLoad(options){
      if(options.workOrderId){
        this.getWorkOrderDetail(options.workOrderId)
      }
      this.editStatus = options.editStatus
      this.mapFormComponents(options.orderCategory);
    },
    methods: {
      // 获取工单详情
      async getWorkOrderDetail(id){
        let res = await workOrderInfo(id);
        this.$set(this, 'workOrderDetail', res.data);
        return this.getDetail(id)
      },
      // 获取记录数据
      async getDetail(workOrderId){
        let res = await foodProductionInfo({ workOrderId });
        this.$set(this, 'categoryDetail', res.data);
      },
      // 走那个表单
      mapFormComponents(orderCategory){
        if(!orderCategory) return;
        switch(orderCategory){
          case '15': this.components = 'OnSiteCheckReport'; break;
          case '14': this.components = 'Session'; break;
        }
      } 
    }
  }
</script>

<template>
  <component :is="components" :workOrderDetail="workOrderDetail" :categoryDetail="categoryDetail" :editStatus="editStatus" />
</template>